
package galcon.players;

import galcon.visuals.components.Fleet;
import galcon.visuals.components.Planet;
import java.awt.Color;

public class Dummybot extends AI {
	public Dummybot (int playerID, Color playerColor) {
		super (playerID, playerColor);
	}
	
	private static final double	frac			= .05;
	private static final int		maxfleets	= 100;
	
	public Command getCommand (Planet [] planets, Fleet [] fleets) {
		// if more than n of my fleets is already out, do nothing
		int count = 0;
		for (Fleet f : fleets)
			if (f.getOwnerID () == playerID) count++;
		if (count >= maxfleets) return null;
		
		// find a planet that I own that has the most ships
		int max = 0, maxID = -1, idx = 0;
		for (Planet p : planets) {
			if (p.getOwnerID () == playerID && p.getShips () > max) {
				max = p.getShips ();
				maxID = idx;
			}
			idx++;
		}
		// I don't own any planets :(
		if (maxID == -1) return null;
		// I don't have enough ships :(
		if ((int) (max * frac) == 0) return null;
		
		// choose the closest planet
		double min = Double.MAX_VALUE;
		int toID = -1;
		idx = 0;
		for (Planet p : planets) {
			if (p.getOwnerID () != playerID
					&& p.getCircle ().getPoint ().distance (planets[maxID].getCircle ().getPoint ())
							/ p.getCircle ().getRadius () < min) {
				min = p.getCircle ().getPoint ().distance (planets[maxID].getCircle ().getPoint ())
						/ p.getCircle ().getRadius ();
				toID = idx;
			}
			idx++;
		}
		// int to = -1, toID = -1;
		// idx = 0;
		// for (Planet p : planets) {
		// if (p.getOwnerID () != playerID && p.getShips () > to) {
		// to = p.getShips ();
		// toID = idx;
		// }
		// idx++;
		// }
		// I own all of the planets :)
		if (toID == -1) return null;
		
		// send frac of my ships from my strongest planet to the weakest planet
		return new Command (new int[] { maxID }, new int[] { toID }, new int[] { (int) (max * frac) }, this);
	}
}
